<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Rounded Nodes Consisting of Two Halves</title>
<meta name="description" content="Nodes consisting of two Panels, using a RoundedTopRectangle and a RoundedBottomRectangle figure." />
<!-- Copyright 1998-2019 by Northwoods Software Corporation. -->
<meta charset="UTF-8">
<script src="../release/go.js"></script>
<script src="../extensions/RoundedRectangles.js"></script>
<script src="../assets/js/goSamples.js"></script>  <!-- this is only for the GoJS Samples framework -->
<script id="code">
  function init() {
    if (window.goSamples) goSamples();  // init for these samples -- you don't need to call this
    var $ = go.GraphObject.make;

    myDiagram =
      $(go.Diagram, "myDiagramDiv",
        {
          initialContentAlignment: go.Spot.Center,
          initialScale: 2.0,
          "undoManager.isEnabled": true
        });

    var NodeInfoSize = new go.Size(50, 25);  // controls the size of each half

    myDiagram.nodeTemplate =
      $(go.Node, "Spot",
        { selectionAdorned: false, locationSpot: go.Spot.Center },
        $(go.Panel, "Auto",
          $(go.Shape, "RoundedRectangle",  // shown when selected
            { stroke: "transparent", strokeWidth: 3, spot1: go.Spot.TopLeft, spot2: go.Spot.BottomRight },
            new go.Binding("stroke", "isSelected", function(s) { return s ? "dodgerblue" : "transparent"; }).ofObject()),
          $(go.Panel,
            $(go.Panel, "Auto",
              { desiredSize: NodeInfoSize },
              $(go.Shape, "RoundedTopRectangle", { fill: "white" }, new go.Binding("fill", "topColor")),
              $(go.TextBlock, new go.Binding("text", "topText"))
            ),
            $(go.Panel, "Auto",
              { desiredSize: NodeInfoSize },
              { position: new go.Point(0, NodeInfoSize.height-1) },  // overlap the top side of this shape with the bottom side of the top shape
              $(go.Shape, "RoundedBottomRectangle", { fill: "white" }, new go.Binding("fill", "bottomColor")),
              $(go.TextBlock, new go.Binding("text", "bottomText"))
            )
          )
        ),
        // decorations...
        $(go.Shape, "FivePointedStar",
          { desiredSize: new go.Size(12, 12), fill: "yellow", alignment: new go.Spot(1, 0, -2, 2), opacity: 0.0 },
          new go.Binding("opacity", "star", function(v) { return v ? 1.0 : 0.0; }))
      );

    load();
  }

  function load() {
    myDiagram.model = go.Model.fromJson(document.getElementById("mySavedModel").value);
  }
</script>
</head>
<body onload="init()">
<div id="sample">
  <div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:400px"></div>
  <p>
    This defines a node template consisting of a top half and a bottom half.
    Each half's text and color are data bound.
    However the size of each node is fixed, so if the text is too long, it will be clipped.
  </p>
  <p>
    The "RoundedTopRectangle" and "RoundedBottomRectangle" figures are defined in
    <a href="../extensions/RoundedRectangles.js">RoundedRectangles.js</a> in the extensions directory.
    See also the <a href="roundedGroups.html" target="_blank">Rounded Groups</a> sample.
  </p>
  <textarea id="mySavedModel" style="width:100%;height:200px">
{
  "nodeDataArray": [
    { "key": "Alpha", "topText": "A", "topColor": "lightgray", "bottomText": "B", "bottomColor": "green" },
    { "key": "Beta", "topText": "C", "bottomText": "D", "bottomColor": "red", "star": true }
  ],
  "linkDataArray": [
    { "from": "Alpha", "to": "Beta" }
  ]
}
  </textarea>
</div>
</body>
</html>